package com.iotteam.androidbase.commen.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.fanwe.library.switchbutton.ISDSwitchButton;
import com.fanwe.library.switchbutton.SDSwitchButton;
import com.iotteam.androidbase.R;

/**
 * Created by vonchenchen on 13/08/2017.
 */

public class SettingView extends RelativeLayout {

    private Context mContext;
    private TextView mTitleText;
    private SDSwitchButton mSDSwitchButton;

    private ISDSwitchButton.OnCheckedChangedCallback mOnCheckedChangedCallback = null;

    public SettingView(Context context) {
        super(context);
        mContext = context;
    }

    public SettingView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();

        View view = View.inflate(mContext, R.layout.view_setting_item, this);
        mTitleText = (TextView) view.findViewById(R.id.tv_title);
        mSDSwitchButton = (SDSwitchButton) view.findViewById(R.id.view_switch);

        mSDSwitchButton.setOnCheckedChangedCallback(new ISDSwitchButton.OnCheckedChangedCallback() {
            @Override
            public void onCheckedChanged(boolean checked, SDSwitchButton view) {
                if(mOnCheckedChangedCallback != null){
                    mOnCheckedChangedCallback.onCheckedChanged(checked, view);
                }
            }
        });
    }

    public void setText(String text){
        mTitleText.setText(text);
    }

    public void setOnCheckedChangedCallback(ISDSwitchButton.OnCheckedChangedCallback callback){
        mOnCheckedChangedCallback = callback;
    }

    public void setSwitchStatus(boolean bool){
        mSDSwitchButton.setChecked(bool, true, true);
    }
}
